var ws = {
    test: function ()
    {
        return 'WebSocket' in window;
    },
    open: function (url)
    {
        if (!ws.test())
            return false;

        socket = new WebSocket('ws://' + url);

        socket.onopen = function ()
        {
            console.log('Connection open!');
        };

        socket.onclose = function ()
        {
            console.log('Disconnecting connection');
        };
    },
    listener: function (callback)
    {
        socket.onmessage = function (evt)
        {
            var received_msg = evt.data;
            console.log(received_msg);
            if (received_msg != 1)
                callback(received_msg);
        }
    },
    send: function (msg)
    {
        socket.send(msg);
    }
}, socket;